package com.richinfo.util;

import com.richinfo.annotation.LogPrint;
import com.richinfo.common.config.Global;
import org.springframework.beans.factory.annotation.Value;

import java.util.Arrays;
import java.util.List;

/**
 * Created on 2017/4/23.
 */
public class UrlUtils {


    private static final String excludeList = Global.getConfig("excludeList");

    private static final String outerUrl =  Global.getConfig("outerUrl");

    public static final String PATTERN_REGEX =  Global.getConfig("PATTERN_REGEX");


    /**
     * 将内网地址转换成外网地址
     *
     * @param url
     */
    public static String transFormUrl(String url) {
        String regex = PATTERN_REGEX;
        List<String> domainList = Arrays.asList(excludeList.split(","));
        boolean flag = false;
        for (int i = 0; i < domainList.size(); i++) {
            String domainFromDb = domainList.get(i);
            if (url.contains(domainFromDb)) {
                flag = true;
                break;
            }
        }
        if (flag) {
            url = url.replaceAll(regex, outerUrl);
        }
        return url;
    }

    public static void main(String[] args) {
        String useless = "http://imsp-test.gmcc.net/bpm/ssoToken.html?mytarget=tydbljdz&wf_docunid=28007eb709de60406a08fa104c43dd149afc&wf_taskid=4e79fa4206897047670a15a03e9bc271110f";
        System.out.println("源地址:"+useless);
        System.out.println("转换后:"+transFormUrl(useless));
    }


}
